Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull down the replace method from ShadowList to Candidates #553

Closed
wants to merge 1 commit into from

Conversation

laeubi
Copy link
Member

@laeubi laeubi commented Mar 7, 2024

The replace method is currently used on one place and the reason we construct a new ShadowList, to remove references to this class the method can simply pulls down to Candidates as it only operates on the internal unmodifiable list.

This also adds a check that if the Capability to replace does not exits it is a noop to call this method instead of running into IndexOutOfBoundsException.

@tjwatson one small step to get rid of direct references to ShadowList as a preliminary step for further refactorings.

@laeubi laeubi requested a review from tjwatson March 7, 2024 05:38
Copy link

github-actions bot commented Mar 7, 2024

Test Results

   28 files  ±0     28 suites  ±0   11m 45s ⏱️ +7s
2 170 tests ±0  2 124 ✅ ±0  46 💤 ±0  0 ❌ ±0 
2 242 runs  ±0  2 196 ✅ ±0  46 💤 ±0  0 ❌ ±0 

Results for commit bab16fe. ± Comparison against base commit f9b6e09.

♻️ This comment has been updated with latest results.

@laeubi
Copy link
Member Author

laeubi commented Mar 7, 2024

All test are green so from my side it would be ready to merge!

@laeubi laeubi force-pushed the pull_down_replace branch from acd09a4 to 711db22 Compare March 8, 2024 06:45
@laeubi
Copy link
Member Author

laeubi commented Mar 8, 2024

@tjwatson thanks for the explanation and hints, I have now adjusted the PR to reflect the original idea of the ShadowList method.

@laeubi laeubi requested a review from tjwatson March 8, 2024 06:48
@laeubi
Copy link
Member Author

laeubi commented Mar 8, 2024

Okay looking at the javadoc it even says

The list returned from {@link #findProviders(Requirement)}

This is already violated as we make a copy of the list (even copied twice) so it can never be the list, I also made the list unmodifiable here and it shows that Equinox at least even inserts items in the list directly, what seems valid but not mandatory, so if a resolve context really uses a cached list and only inserts items in this cache, or even relies on identity lookup this will break.

This also seems not really covered by the TCK, so I think before going further here we first need a TCK, then make sure Felix passes the TCK and then go on.

Taking this into account it seems the resolver would need to build the datastructure in a two step way, what likely will also make it easier to "finalize it":

  1. Operate on the list returned from findProviders(Requirement) without wrapping and / or copy and do not replace / shadow things, but insert HostedCapabilities as needed.
  2. Create a new (finalized) model where we make the copy as well as replace / shadow things because after this phase we should not insert things anymore.

There is just one tricky part org.apache.felix.resolver.Candidates.processCandidates(LinkedList<Resource>, Requirement, List<Capability>) also calls insertHostedCapability but in this case relies on that the list is updated automatically, I'm not sure this is really covered by the spec!

@laeubi laeubi force-pushed the pull_down_replace branch from 711db22 to 22fe7be Compare March 8, 2024 07:41
@laeubi
Copy link
Member Author

laeubi commented Mar 8, 2024

copy[i] = ((ShadowedCapability) capability).getShadowed();
}
}
int insertIdx = context.insertHostedCapability(Arrays.asList(copy), toInsertCapability);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems odd and not in the spirit of the specification when multiple hosted capabilities are inserted into the list. The ResolveContext will keep getting the same original list back and it will not have the past hosted capabilities there that the ResolveContext had inserted. This means the ResolveContext will not have any control over the order of the inserted HostedCapability objects in relation to each other.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now fixed that, the main problem is that Felix resolver is violation the contract of insertHosteCapability, I added a TCK that shows the problem, but at least this should work as before.

The replace method is currently used on one place and the reason we
construct a new ShadowList, to remove references to this class the
method can simply pulls down to Candidates as it only operates on the
internal unmodifiable list.

This also adds a check that if the Capability to replace does not exits
it is a noop to call this method instead of running into
IndexOutOfBoundsException.
@laeubi laeubi force-pushed the pull_down_replace branch from 22fe7be to bab16fe Compare March 8, 2024 15:57
@laeubi
Copy link
Member Author

laeubi commented Apr 30, 2024

I'll close this for now and maybe came up with a different aproach.

@laeubi laeubi closed this Apr 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants